package com.icode.core.model.house;

import com.icode.core.model.AbstractEntity;
import com.icode.core.model.user.UserInfo;

import javax.persistence.*;
import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-9-1
 * Time: 上午10:06
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "my_house")
public class MyHouse extends AbstractEntity {

    @ManyToOne
    @JoinColumn(name = "house_info_id")
    private HouseInfo houseInfo;

    @ManyToOne
    @JoinColumn(name = "house_week_id")
    private HouseWeek houseWeek;

    @ManyToOne
    @JoinColumn(name = "user_info_id")
    private UserInfo userInfo;

    /*
    means:How many did i buy
     */
    @Column(name = "buy_num")
    private String buyNum;

    @Column(name = "my_house_status")
    @Enumerated(EnumType.STRING)
    private MyHouseStatus myHouseStatus;

    @Column(columnDefinition = "bit")
    private boolean usable = true;
    @Column(name = "exchange_house", columnDefinition = "bit")
    private boolean exchangeHouse = false;

    @OneToMany
    @JoinColumn(name = "my_house_id")
    private List<Rent> rents;

    private int days;

    public MyHouse() {
    }

    public MyHouse(HouseInfo houseInfo, HouseWeek houseWeek, UserInfo userInfo, MyHouseStatus myHouseStatus) {
        this.houseInfo = houseInfo;
        this.houseWeek = houseWeek;
        this.userInfo = userInfo;
        this.myHouseStatus = myHouseStatus;
    }

    public MyHouse(HouseInfo houseInfo, HouseWeek houseWeek, UserInfo userInfo, String buyNum, MyHouseStatus myHouseStatus) {
        this.houseInfo = houseInfo;
        this.houseWeek = houseWeek;
        this.userInfo = userInfo;
        this.buyNum = buyNum;
        this.myHouseStatus = myHouseStatus;
    }

    public String buyNum() {
        return buyNum;
    }

    public HouseInfo houseInfo() {
        return houseInfo;
    }

    public HouseWeek houseWeek() {
        return houseWeek;
    }

    public UserInfo userInfo() {
        return userInfo;
    }

    public MyHouseStatus myHouseStatus() {
        return myHouseStatus;
    }

    public void setMyHouseStatus(MyHouseStatus exchangePoolStatus) {
        this.myHouseStatus = exchangePoolStatus;
    }

    public boolean usable() {
        return usable;
    }

    public boolean exchangeHouse() {
        return exchangeHouse;
    }

    public int days() {
        return days;
    }

    public void setUsable(boolean usable) {
        this.usable = usable;
    }

    public void setExchangeHouse(boolean exchangeHouse) {
        this.exchangeHouse = exchangeHouse;
    }

    public void updateStatus(MyHouseStatus status) {
        this.myHouseStatus = status;
    }

    public List<Rent> rents() {
        return rents;
    }

    public void initMyHouseStatus(MyHouseStatus status) {
        this.myHouseStatus = status;
    }

    public void updateDays(int days) {
        this.days += days;
    }
}
